package com.dao.impl;

import com.bean.Viedo;
import com.dao.BaseDao;
import com.dao.ViedoDao;

import java.util.List;

public class ViedoImpl extends BaseDao implements ViedoDao {
//视频添加
    @Override
    public int addViedo(Viedo viedo) {
        String sql = "INSERT INTO `viedo`(`vname`,`vtype`,`vdesc`,`pic`,`number`,`idDown`,`upLoader`,`checkid`,`uploaddata`,`checkdata`,`favoriteNum`,`likeNum`)VALUES (?,?,?,?,?,?,?,?,?,?,?,?)";
        return update(sql, viedo.getVname(), viedo.getVtype(), viedo.getVdesc(), viedo.getPic(), viedo.getNumber(), viedo.getIdDown(), viedo.getUpLoader(), viedo.getCheckid(), viedo.getUploaddata(), viedo.getCheckdata(), viedo.getFavoriteNum(), viedo.getLikeNum());
    }
//视频删除
    @Override
    public int deleteViedoid(int id) {
        String sql = "DELETE FROM `viedo`WHERE `id`=?";
        return update(sql, id);
    }
//视频修改
    @Override
    public int updataViedo(Viedo viedo) {
        String sql = "UPDATE viedo SET `vname`=?,`vtype`=?,`vdesc`=?,`pic`=?,`number`=?,`idDown`=?,`upLoader`=?,`checkid`=?,`uploaddata`=?,`checkdata`=?,`favoriteNum`=?,`likeNum`=? WHERE `id`=? ";
        return update(sql,viedo.getVname(), viedo.getVtype(), viedo.getVdesc(), viedo.getPic(), viedo.getNumber(), viedo.getIdDown(), viedo.getUpLoader(), viedo.getCheckid(), viedo.getUploaddata(), viedo.getCheckdata(), viedo.getFavoriteNum(), viedo.getLikeNum(),viedo.getId());
    }
//根据名字查询
    @Override
    public List<Viedo> queryViedovname(String vname) {
        String sql = "SELECT `id`,`vname`,`vtype`,`vdesc`,`pic`,`number`,`idDown`,`upLoader`,`checkid`,`uploaddata`,`checkdata`,`favoriteNum`,`likeNum` FROM `viedo` WHERE  vname LIKE  '%?%'";
        return queryForList(Viedo.class, sql, vname);

    }
//查询全部视频
    @Override
    public List<Viedo> queryViedoAll() {
        String sql = "SELECT `id`,`vname`,`vtype`,`vdesc`,`pic`,`number`,`idDown`,`upLoader`,`checkid`,`uploaddata`,`checkdata`,`favoriteNum`,`likeNum` FROM `viedo`";
        return queryForList(Viedo.class, sql);
    }
//查询总页数
    @Override
    public Integer queryForPageTotalCount() {
        String sql = "select count(*) from `viedo`";
        //调用查询单个sql语句，查询数量
        Number count = (Number) queryForSingleValue(sql);
        return count.intValue(); //intValue方法把Number类型转成Integer类型
    }
//查询某页的数据
    @Override
    public List<Viedo> queryForPageItems(int begin, int pageSize) {
        String sql = "SELECT `id``vname`,`vtype`,`vdesc`,`pic`,`number`,`idDown`,`upLoader`,`checkid`,`uploaddata`,`checkdata`,`favoriteNum`,`likeNum` FROM `viedo` LIMIT ?,?";
        return queryForList(Viedo.class, sql, begin, pageSize);
    }
//按播放量查询页面总数
    @Override
    public Integer queryForPageTotalCountByPrice(int min, int max) {
        String sql = "select count(*) from viedo where number between ? and ?";
        Number count = (Number) queryForSingleValue(sql, min, max);
        return count.intValue();
    }
   // 按价格查询页面项目
//    @Override
//    public List<Viedo> queryForPageItemsByPrice(int begin, int pageSize, int min, int max) {
//        String sql = "select `id`,`name`,`producer`,`price`,`sales`,`stock`,`img_path` " +
//                "from t_goods where price between ? and ? order by price limit ?,?";
//        return queryForList(Viedo.class, sql, min, max, begin, pageSize);
//    }
}
